# coding=utf-8
# 代码文件：chapter5/ch5.2.4.py

import xlwings as xw

app = xw.App(visible=True, add_book=False)
f = r'data/北京房价数据.xlsx'
wb = app.books.open(f)

sheet1 = wb.sheets[0]

pricerng = sheet1.range('I2').options(expand='down')        # 选择单价列

value = wb.app.api.WorksheetFunction.Max(pricerng.value)    # 计算单价列最大值
print('最大值：', value)

rng = sheet1.range('A1').current_region

rng.api.AutoFilter(Field := 9,                              # 对第9列进行过滤处理
                   Criteria1 := value, )
